package com.aizhixin.lab.docker.service;

import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.docker.entity.LastOperation;
import com.aizhixin.lab.docker.repository.LastOperationRepository;

import java.util.UUID;

public class ImageRunnable implements Runnable {
    private DockerContainerService dockerContainerService;
    private LastOperationRepository repository;
    private AccountDTO dto;
    private String containerIp;
    private String token;
    private String courseId;

    public ImageRunnable(DockerContainerService dockerContainerService, LastOperationRepository repository, AccountDTO dto, String containerIp, String token,String courseId) {
        this.dockerContainerService = dockerContainerService;
        this.repository = repository;
        this.dto = dto;
        this.containerIp = containerIp;
        this.token = token;
        this.courseId=courseId;
    }

    @Override
    public void run() {
        repository.deleteByUserId(dto.getId());
//        String save = dockerContainerService.save(containerIp, dto.getName(), dto.getUserName(), token);
        LastOperation lastOperation = new LastOperation();
        lastOperation.setId(UUID.randomUUID().toString());
        lastOperation.setImagesName(dto.getUserName());
//        lastOperation.setImagesVersion(save);
        lastOperation.setUserId(dto.getId());
        repository.save(lastOperation);
    }
}
